//
//  XMLParserWorker.h
//  OR_1
//
//  Created by Luboš Kulič on 8/21/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>


@class Stack;

@interface DataElement : NSObject {
	@public
	NSString * name;
	NSString * data;
}

+(DataElement *)elementWithName:(NSString *)name_ Data:(NSString *)data_;

-(id)initWithName:(NSString *)name_ Data:(NSString *)data_;

-(NSString *) name;
-(NSString *) data;


@end




/**
 Generic parser object.
 
 Parses given XML element, when subelement found, it tries to pass control to appropriate worker (determined by +getParserForElement:). 
 When no worker registered, it is assumed that current worker can process the data and standard process is started - i.e. element 
 name stored into a stack as well as particular text data of the element.
 When element parsed by this particular worker ends, it calls callback method for business work (provided by subclasses).
 
 */
@interface XMLParserWorker : NSObject {
	
@protected
	NSString * rootElementName_;
	
	NSDictionary * translator;
	
	/// contains names of the elements (NSString)
	Stack * elementStack; // -- DO WE REALLY NEED THAT?
	
	/// contains data contained within the elements (NSMutableString)
	Stack * dataStack;
	
	NSMutableDictionary * retData;
	
	XMLParserWorker * previousWorker;
	
	NSString * elementName;
	

}

/// returns unique name of element parsed by a particular subclass
+(NSString *) parsedElementName ;


/// inherited by every subclass
/// uses class method parsedElementName - every subclass must reimplement for proper use
+(void) load;



// probably not neccessary - only for private use
// deprecated
+(void) registerParser:(Class)parser ForElement:(NSString *) elementName DEPRECATED_ATTRIBUTE;


// When given element should be parsed as a subelement (i.e. there should be created new node in the data hierarchy),
// the method returns the new parser worker (appropriate for given element - either complex, simple or array)
-(XMLParserWorker *) getParserForElement:(NSString *)elementName;




/**********************************************************************************************/


-(id) init;

// TODO - move to predecessor (generalize)
-(id) initWithName:(NSString *) name;

-(void)initAuxData;



/// Called by generic worker every time a new subelement will be parsed by another worker.
/// The parent worker is supposed to store the subelement parser into its own datastructures, 
/// it is aimed as a callback for subclasses to reimplement. 
-(void) parserWillStartSubelement:(NSString *)elementName withWorker:(XMLParserWorker *)newWorker;

/// Called by generic worker every time an element parsed by the particular subclass ends.
/// Aimed as a callback for subclasses to reimplement.
-(void) parserDidEndRootElementWithData:(NSString *)parsedElementData;

-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict;

-(void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName;

-(void) parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock;

-(void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;

-(void)parser:(NSXMLParser *)parser foundIgnorableWhitespace:(NSString *)whitespaceString;


@end
